package com.cn.algorithm02.class15;

/***
 * @author: hels
 * @description: 道路上最小放灯数量问题：
 * 一个字符串x和.组成，x表示墙壁不可以放置路灯，.表示道路需要被照亮且可以放置路灯
 * 求最小的放置路灯的数量？
 **/
public class C04_MinLights {
    public static void main(String[] args) {
        String str = "x...x...x..x..x..";
        System.out.println(minLights(str));
    }

    public static int minLights(String str) {
        char[] roads = str.toCharArray();

        int i = 0;
        int lights = 0;

        while (i < roads.length) {
            if (roads[i] == 'x') {
                i = i + 1;
            } else {
                lights++;
                if (i + 1 == roads.length) {
                    break;
                } else if (roads[i + 1] == 'x') {
                    i = i + 2;
                } else {
                    i = i + 3;
                }
            }
        }

        return lights;
    }
}
